package iss.java;

import iss.java.list.MyList;
import iss.java.list.Node;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by wenke on 2016/9/16.
 */
public class Main_B {
    public static MyList mylist=new MyList();
    public static Lock lock=new ReentrantLock();
    public static void main(String[] args) throws InterruptedException {
        // TODO: Write a multithreaded testcase against requirement B.
        // NOTE: Testcase for requirement C is not required.
        Thread a=new Thread(){
            @Override
            public void run(){
                lock.lock();
                try {
                    mylist.insert(mylist.getTail(),5);
                }
                finally {
                    lock.unlock();
                }
            }
        };
        Thread b=new Thread(){
            @Override
                public  void  run(){
                    lock.lock();
                    try {
                        mylist.remove(mylist.getTail());
                    }
                    finally {
                        lock.unlock();
                    }

            }
        };
        a.start();
        b.start();
        Thread.sleep(10000);
        System.out.println("the tail of the list is"+mylist.getTail().getData());
    }
}
